<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>toNow() | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>toNow()</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>toNow()</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/displaying/tonow/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/04-displaying/04-tonow.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().toNow();
moment().toNow(Boolean);
</code></pre>

							</div>
<p>&#x663E;&#x793A;&#x65F6;&#x95F4;&#x7684;&#x5E38;&#x7528;&#x65B9;&#x6CD5;&#x662F;&#x901A;&#x8FC7; <code>moment#toNow</code> &#x5904;&#x7406;&#x3002;
&#x6709;&#x65F6;&#x79F0;&#x4E3A;&#x65F6;&#x95F4;&#x95F4;&#x9694;&#x6216;&#x76F8;&#x5BF9;&#x65F6;&#x95F4;&#x3002;</p>
<p>&#x8FD9;&#x7C7B;&#x4F3C;&#x4E8E; <a href="javascript:window.open('http://nodejs.cn/s/YjxL9t');" target="_blank" rel="nofollow"><code>moment.fromNow</code></a>&#xFF0C;&#x4F46;&#x7ED9;&#x51FA;&#x76F8;&#x53CD;&#x7684;&#x95F4;&#x9694;&#xFF1A;<code>a.fromNow() = - a.toNow()</code>&#x3002;</p>
<p>&#x8FD9;&#x7C7B;&#x4F3C;&#x4E8E; <a href="javascript:window.open('http://nodejs.cn/s/rGGgHy');" target="_blank" rel="nofollow"><code>moment.to</code></a>&#xFF0C;&#x4F46;&#x5728;&#x5F53;&#x524D;&#x65F6;&#x95F4;&#x6709;&#x7279;&#x6B8A;&#x60C5;&#x51B5;&#x3002;
&#x5982;&#x679C;&#x8981;&#x63A7;&#x5236;&#x95F4;&#x9694;&#x7684;&#x4E24;&#x4E2A;&#x7AEF;&#x70B9;&#xFF0C;&#x5219;&#x4F7F;&#x7528; <code>moment.to</code>&#x3002;</p>
<pre><code class="language-javascript">moment([2007, 0, 29]).toNow(); // 4 &#x5E74;&#x5185;
</code></pre>
<p>&#x5982;&#x679C;&#x4F20;&#x5165; <code>true</code>&#xFF0C;&#x5219;&#x53EF;&#x4EE5;&#x83B7;&#x53D6;&#x4E0D;&#x5E26;&#x524D;&#x7F00;&#x7684;&#x503C;&#x3002;</p>
<pre><code class="language-javascript">moment([2007, 0, 29]).toNow();     // 4 &#x5E74;&#x5185;
moment([2007, 0, 29]).toNow(true); // 4 &#x5E74;
</code></pre>
<p>&#x57FA;&#x672C;&#x7684;&#x5B57;&#x7B26;&#x4E32;<a href="javascript:window.open('http://nodejs.cn/s/YdNJNH');" target="_blank" rel="nofollow">&#x7531;&#x5F53;&#x524D;&#x7684;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x81EA;&#x5B9A;&#x4E49;</a>&#x3002;</p>
<p>&#x4E0B;&#x8868;&#x6982;&#x8FF0;&#x4E86;&#x6BCF;&#x4E2A;&#x65F6;&#x95F4;&#x957F;&#x5EA6;&#x663E;&#x793A;&#x7684;&#x5B57;&#x7B26;&#x4E32;&#x7684;&#x7EC6;&#x5206;&#x3002;</p>
<table class="table table-striped table-bordered">
  <thead>
    <tr>
      <th>&#x8303;&#x56F4;</th>
      <th>&#x952E;</th>
      <th>&#x6837;&#x672C;&#x8F93;&#x51FA;</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>0 &#x81F3; 44 &#x79D2;</td>
      <td>s</td>
      <td>&#x51E0;&#x79D2;&#x5185;</td>
    </tr>
    <tr>
      <td>45 &#x81F3; 89 &#x79D2;</td>
      <td>m</td>
      <td>1 &#x5206;&#x949F;&#x5185;</td>
    </tr>
    <tr>
      <td>90 &#x79D2;&#x81F3; 44 &#x5206;&#x949F;</td>
      <td>mm</td>
      <td>2 &#x5206;&#x949F;&#x5185; ... 44 &#x5206;&#x949F;&#x5185;</td>
    </tr>
    <tr>
      <td>45 &#x81F3; 89 &#x5206;&#x949F;</td>
      <td>h</td>
      <td>1 &#x5C0F;&#x65F6;&#x5185;</td>
    </tr>
    <tr>
      <td>90 &#x5206;&#x949F;&#x81F3; 21 &#x5C0F;&#x65F6; </td>
      <td>hh</td>
      <td>2 &#x5C0F;&#x65F6;&#x5185; ... 21 &#x5C0F;&#x65F6;&#x5185;</td>
    </tr>
    <tr>
      <td>22 &#x81F3; 35 &#x5C0F;&#x65F6;</td>
      <td>d</td>
      <td>1 &#x5929;&#x5185;</td>
    </tr>
    <tr>
      <td>36 &#x5C0F;&#x65F6;&#x81F3; 25 &#x5929;</td>
      <td>dd</td>
      <td>2 &#x5929;&#x5185; ... 25 &#x5929;&#x5185;</td>
    </tr>
    <tr>
      <td>26 &#x81F3; 45 &#x5929;</td>
      <td>M</td>
      <td>1 &#x4E2A;&#x6708;&#x5185;</td>
    </tr>
    <tr>
      <td>45 &#x81F3; 319 &#x5929;</td>
      <td>MM</td>
      <td>2 &#x4E2A;&#x6708;&#x5185; ... 10 &#x4E2A;&#x6708;&#x5185;</td>
    </tr>
    <tr>
      <td>320 &#x81F3; 547 &#x5929; (1.5 &#x5E74;)</td>
      <td>y</td>
      <td>1 &#x5E74;&#x5185;</td>
    </tr>
    <tr>
      <td>548 &#x5929;+</td>
      <td>yy</td>
      <td>2 &#x5E74;&#x5185; ... 20 &#x5E74;&#x5185;</td>
    </tr>
  </tbody>
</table>
<p>&#x4ECE; <strong>2.10.3</strong> &#x7248;&#x672C;&#x5F00;&#x59CB;&#xFF0C;&#x5982;&#x679C;&#x76EE;&#x6807; moment &#x5BF9;&#x8C61;&#x65E0;&#x6548;&#xFF0C;&#x5219;&#x7ED3;&#x679C;&#x4E3A;&#x672C;&#x5730;&#x5316;&#x7684;&#x65E0;&#x6548;&#x65E5;&#x671F;&#x5B57;&#x7B26;&#x4E32;&#x3002;</p>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">moment().toNow();
moment().toNow(Boolean);
</code></pre>

							</div>
<p>A common way of displaying time is handled by <code>moment#toNow</code>. This is sometimes called timeago or relative time.</p>
<p>This is similar to <a href="index.html#/displaying/fromnow/" target="_blank" rel="nofollow"><code>moment.fromNow</code></a>, but gives
the opposite interval: <code>a.fromNow() = - a.toNow()</code>.</p>
<p>This is similar to <a href="index.html#/displaying/to/" target="_blank" rel="nofollow"><code>moment.to</code></a>, but is special-cased
for the current time. Use <code>moment.to</code>, if you want to control the two end
points of the interval.</p>
<pre><code class="language-javascript">moment([2007, 0, 29]).toNow(); // in 4 years
</code></pre>
<p>If you pass <code>true</code>, you can get the value without the prefix.</p>
<pre><code class="language-javascript">moment([2007, 0, 29]).toNow();     // in 4 years
moment([2007, 0, 29]).toNow(true); // 4 years
</code></pre>
<p>The base strings are <a href="#/customization/relative-time/" target="_blank" rel="nofollow">customized by the current locale</a>.</p>
<p>The breakdown of which string is displayed for each length of time is outlined in the table below.</p>
<table class="table table-striped table-bordered">
  <thead>
    <tr>
      <th>Range</th>
      <th>Key</th>
      <th>Sample Output</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>0 to 44 seconds</td>
      <td>s</td>
      <td>in seconds</td>
    </tr>
    <tr>
      <td>45 to 89 seconds</td>
      <td>m</td>
      <td>in a minute</td>
    </tr>
    <tr>
      <td>90 seconds to 44 minutes</td>
      <td>mm</td>
      <td>in 2 minutes ... in 44 minutes</td>
    </tr>
    <tr>
      <td>45 to 89 minutes</td>
      <td>h</td>
      <td>in an hour</td>
    </tr>
    <tr>
      <td>90 minutes to 21 hours </td>
      <td>hh</td>
      <td>in 2 hours ... in 21 hours</td>
    </tr>
    <tr>
      <td>22 to 35 hours</td>
      <td>d</td>
      <td>in a day</td>
    </tr>
    <tr>
      <td>36 hours to 25 days</td>
      <td>dd</td>
      <td>in 2 days ... in 25 days</td>
    </tr>
    <tr>
      <td>26 to 45 days</td>
      <td>M</td>
      <td>in a month</td>
    </tr>
    <tr>
      <td>45 to 319 days</td>
      <td>MM</td>
      <td>in 2 months ... in 10 months</td>
    </tr>
    <tr>
      <td>320 to 547 days (1.5 years)</td>
      <td>y</td>
      <td>in a year</td>
    </tr>
    <tr>
      <td>548 days+</td>
      <td>yy</td>
      <td>in 2 years ... in 20 years</td>
    </tr>
  </tbody>
</table>
<p>From version <strong>2.10.3</strong>, if the target moment object is invalid the result is
the localized Invalid date string.</p>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>